//
//  CellForNight.m
//  MY Project For Sport
//
//  Created by admin on 16/2/18.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "CellForNight.h"
#import <DKNightVersion.h>

#define WEIGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667

@interface CellForNight ()


@end


@implementation CellForNight

- (void)dealloc {

    [_labelForTitle release];
    [_nightSwitch release];

    [super dealloc];

}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.contentView.dk_backgroundColorPicker = DKColorWithRGB (0xffffff, 0x343434);
        
        [self createSubView];
        
        
    }


    return self;


}

- (void)createSubView {

    self.labelForTitle = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForTitle];
    [_labelForTitle release];
    
    
    self.nightSwitch = [[UISwitch alloc] init];
    [self.contentView addSubview:self.nightSwitch];
    [_nightSwitch release];
    
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"ISNIGHT"]) {
        self.nightSwitch.on = YES;
    }else {
        self.nightSwitch.on = NO;
        
    }
}




- (void)layoutSubviews {


    [super layoutSubviews];
    
    self.labelForTitle.frame = CGRectMake(10 * WEIGHTT, 20 * HEIGHTT, self.contentView.frame.size.width / 3, self.contentView.frame.size.height - 40 * HEIGHTT);
    
    self.labelForTitle.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    
    self.nightSwitch.frame = CGRectMake(self.contentView.frame.size.width / 10 * 8, 20 * HEIGHTT, self.contentView.frame.size.width / 10 * 3, self.contentView.frame.size.height - 40 * HEIGHTT);
    [self.nightSwitch addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];

    

}


- (void)change:(UISwitch *)switchIs {
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    
    
    if ([DKNightVersionManager currentThemeVersion] == DKThemeVersionNight) {
        [DKNightVersionManager dawnComing];
    } else {
        [DKNightVersionManager nightFalling];
    }
    
    
    // 保存状态 , 程序再次启动时的偏好设置
    [user setBool:switchIs.on forKey:@"ISNIGHT"];
    [user synchronize];
    
    
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
